package com.viettel.pon.DAO;

import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.util.Log;

import com.viettel.pon.form.InputLoginForm;
import com.viettel.pon.form.PoleForm;
import com.viettel.pon.form.PoleListForm;
import com.viettel.pon.form.ResultLoginForm;

public class SyncPonDAO {
	
	
public String SyncPoles(String sid,List<PoleForm> lstPoles) {
		
	String resultString="";
		String SOAP_ACTION1 = "http://webservice.pon.viettel.com/PonWS/importPoleRequest";

		String NAMESPACE = "http://webservice.pon.viettel.com/";

		String METHOD_NAME1 = "importPole";

		String URL = "http://localhost:8084/PONWebservice/PonWS?wsdl";

		String strResult = "";
		// Initialize soap request + add parameters
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);

		PoleListForm input= new PoleListForm();
		input.setSessionId(sid);
		input.setListPoles(lstPoles);
		
		 PropertyInfo listProp =new PropertyInfo();
		 listProp.setName("listPole");
		 listProp.setValue(input);
		 listProp.setType(input.getClass());
		 
		 request.addProperty("sessionId",sid);
		 request.addProperty(listProp);
		// Declare the version of the SOAP request
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		envelope.dotNet = false;
		try {
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			// this is the actual part that will call the webservice
			androidHttpTransport.call(SOAP_ACTION1, envelope);
			// Get the SoapResult from the envelope body.
			SoapObject result = null;
			if (envelope.bodyIn instanceof SoapFault) {
				String str = ((SoapFault) envelope.bodyIn).faultstring;
				Log.e("result", str);
			} else {
				result = (SoapObject) envelope.bodyIn;
			}
			if (result != null) {
			Log.e("total", String.valueOf(result.getPropertyCount()));
			for (int i = 0; i < result.getPropertyCount(); i++) {
				Object property = result.getProperty(i);
				if (property instanceof SoapObject) {
					SoapObject resultList = (SoapObject) property;
					
				}
			}
			} else {
				resultString="NOK";
			}

		} catch (Exception e) {
			e.printStackTrace();
			resultString="NOK";
		}
		return resultString;
	}
}
